<?php

namespace App\Http\Controllers;

use App\Library\Lock;
use App\Library\Requests\Base\SerialNumberRequest;
use App\Library\Requests\ProductOrderReturn\AgreeRefundProductRequest;
use App\Library\Requests\ProductOrderReturn\ProductOrderReturnAddExpressRequest;
use App\Library\Requests\ProductOrderReturn\ProductOrderReturnApplyRequest;
use App\Library\Requests\ProductOrderReturn\ProductOrderReturnAuditRequest;
use App\Library\Requests\ProductOrderReturn\ProductOrderReturnPageRequest;
use App\Library\Requests\ProductOrderReturn\ProductOrderReturnSellerPageRequest;
use App\Library\Requests\ProductOrderReturn\ProductOrderReturnUserPageRequest;
use App\Library\Service\ProductOrderReturnService;
use Illuminate\Http\JsonResponse;

class ProductOrderReturnController extends BaseController
{
    /**
     * @param ProductOrderReturnService $service
     */
    public function __construct(ProductOrderReturnService $service)
    {
        $this->service = $service;
    }

    /**
     * paging
     * @param ProductOrderReturnPageRequest $request
     * @return JsonResponse
     */
    public function paging(ProductOrderReturnPageRequest $request): JsonResponse
    {
        return $this->service->paging($request);
    }

    /**
     * userPaging
     * @param ProductOrderReturnUserPageRequest $request
     * @return JsonResponse
     */
    public function userPaging(ProductOrderReturnUserPageRequest $request): JsonResponse
    {
        return $this->service->userPaging($request);
    }

    /**
     * sellerPaging
     * @param ProductOrderReturnSellerPageRequest $request
     * @return JsonResponse
     */
    public function sellerPaging(ProductOrderReturnSellerPageRequest $request): JsonResponse
    {
        return $this->service->sellerPaging($request);
    }

    /**
     * detail
     * @param SerialNumberRequest $request
     * @return JsonResponse
     */
    public function detail(SerialNumberRequest $request): JsonResponse
    {
        return $this->service->detail($request);
    }

    /**
     * userDetail
     * @param SerialNumberRequest $request
     * @return JsonResponse
     */
    public function userDetail(SerialNumberRequest $request): JsonResponse
    {
        return $this->service->userDetail($request);
    }

    /**
     * sellerDetail
     * @param SerialNumberRequest $request
     * @return JsonResponse
     */
    public function sellerDetail(SerialNumberRequest $request): JsonResponse
    {
        return $this->service->sellerDetail($request);
    }

    /**
     * apply
     * @param ProductOrderReturnApplyRequest $request
     * @return JsonResponse
     */
    public function apply(ProductOrderReturnApplyRequest $request): JsonResponse
    {
        return Lock::get(__CLASS__ . __FUNCTION__ . $request->serialNumber, function () use ($request) {
            return $this->service->apply($request);
        });
    }

    /**
     * addLogistic
     * @param ProductOrderReturnAddExpressRequest $request
     * @return JsonResponse
     */
    public function addExpress(ProductOrderReturnAddExpressRequest $request): JsonResponse
    {
        return Lock::get(__CLASS__ . __FUNCTION__ . $request->serialNumber, function () use ($request) {
            return $this->service->addExpress($request);
        });
    }

    /**
     * audit
     * @param ProductOrderReturnAuditRequest $request
     * @return JsonResponse
     */
    public function audit(ProductOrderReturnAuditRequest $request): JsonResponse
    {
        return Lock::get(__CLASS__ . __FUNCTION__ . $request->serialNumber, function () use ($request) {
            return $this->service->audit($request);
        });
    }

    /**
     * confirm
     * @param SerialNumberRequest $request
     * @return JsonResponse
     */
    public function confirm(SerialNumberRequest $request): JsonResponse
    {
        return Lock::get(__CLASS__ . __FUNCTION__ . $request->serialNumber, function () use ($request) {
            return $this->service->confirm($request);
        });
    }

    /**
     * delete
     * @param SerialNumberRequest $request
     * @return JsonResponse
     *
     */
    public function delete(SerialNumberRequest $request): JsonResponse
    {
        return Lock::get(__CLASS__ . __FUNCTION__ . $request->serialNumber, function () use ($request) {
            return $this->service->delete($request);
        });
    }

    /**
     * 查看物流信息
     * @param SerialNumberRequest $request
     * @return JsonResponse
     *
     */
    public function logistics(SerialNumberRequest $request): JsonResponse
    {
        return $this->service->logistics($request);
    }

    public function sellerAddressList(): JsonResponse
    {
        return $this->service->sellerAddressList();
    }

    /**
     * 同意售后并等待收货
     * @param AgreeRefundProductRequest $request
     * @return JsonResponse
     *
     */
    public function agreeRefundProduct(AgreeRefundProductRequest $request): JsonResponse
    {
        return $this->service->agreeRefundProduct($request);
    }

    /**
     * 取消退货
     * @param SerialNumberRequest $request
     * @return mixed
     *
     */
    public function cancelRefundProduct(SerialNumberRequest $request): JsonResponse
    {
        return $this->service->cancelRefundProduct($request);
    }

    /**
     * 用户取消售后申请
     * @param SerialNumberRequest $request
     * @return JsonResponse
     *
     */
    public function cancel(SerialNumberRequest $request): JsonResponse
    {
        return $this->service->cancel($request);
    }
}
